<template>
    <el-dialog title="添加检验项目" :close-on-click-modal="false" :visible.sync="visible" :append-to-body="true"
        class="SHZY-dialog SHZY-dialog_center" lock-scroll width="80%">
        <el-form ref="elForm" v-if="this.dataForm.sampleId == ''" size="small" label-width="95px" label-position="left"
            :inline="true" :model="dataForm" :rules="rules">
            <el-form-item label="抽样方案" prop="samplingType">
                <el-select v-model="dataForm.samplingType" placeholder="抽样方案" clearable>
                    <el-option v-for="(item, index) in sampleTypeData" :key="index" :label="item.fullName"
                        :value="item.enCode" />
                </el-select>
            </el-form-item>
            <el-form-item label="检验水平" prop="gLevel" v-if="dataForm.samplingType == '1'">
                <el-select v-model="dataForm.gLevel" placeholder="检验水平" clearable>
                    <el-option v-for="(item, index) in gLevelData" :key="index" :label="item.fullName"
                        :value="item.enCode" />
                </el-select>
            </el-form-item>
            <el-form-item label="国际严格度" prop="gStringency" v-if="dataForm.samplingType == '1'">
                <el-select v-model="dataForm.gStringency" placeholder="国际严格度" clearable>
                    <el-option v-for="(item, index) in gStringencyData" :key="index" :label="item.fullName"
                        :value="item.enCode" />
                </el-select>
            </el-form-item>
            <el-form-item label="国际质量限" prop="gQualityLimit" v-if="dataForm.samplingType == '1'">
                <el-select v-model="dataForm.gQualityLimit" placeholder="国际质量限" clearable>
                    <el-option v-for="(item, index) in gQualityLimitData" :key="index" :label="item.fullName"
                        :value="item.enCode" />
                </el-select>
            </el-form-item>
            <el-form-item label="抽样数量" prop="fixedSamplingQty"
                v-if="dataForm.samplingType == '2' || dataForm.samplingType == '5'">
                <el-input v-model='dataForm.fixedSamplingQty' clearable required :style='{ "width": "100%" }'>
                </el-input>
            </el-form-item>
            <el-form-item label="抽样比例" prop="fixedRatio" v-if="dataForm.samplingType == '3'">
                <el-input v-model='dataForm.fixedRatio' clearable required :style='{ "width": "100%" }'>
                </el-input>
            </el-form-item>
            <el-form-item label="自定义AQL" prop="aQL" v-if="dataForm.samplingType == '4'">
                <SHZY-select :list="aqlData" v-model:bindValue="dataForm.aQL" label="name" value="id"></SHZY-select>
            </el-form-item>
        </el-form>

        <el-form ref="tableForm" :model="dataForm" :rules="tableRules" :inline="true">
            <el-table :data="dataForm.detailData" size='mini' ref="dragTable" max-height="350px"
                :row-key="row => row.index">
                <el-table-column align="center" label="拖动" width="50">
                    <template>
                        <i class="drag-handler icon-ym icon-ym-darg" style="cursor: move;font-size:20px" title='点击拖动' />
                    </template>
                </el-table-column>
                <el-table-column type="index" width="50" label="序号" align="center" />
                <el-table-column prop="field" label="检验项目" width="200">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + ''" :rules="tableRules.innspectionCode">
                            <SHZY-select :list="projectData" v-model:bindValue="scope.row.innspectionCode"
                                label="innspectionName" value="id"></SHZY-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="检验条目" width="200">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + ''" :rules="tableRules.innspectionEntry">
                            <SHZY-select :list="itemData" :linkData="scope.row.innspectionCode" linkDataName="ItemsId"
                                v-model:bindValue="scope.row.innspectionEntry" label="innspectionName"
                                value="id"></SHZY-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="检验方法" width="200">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + '.innspectionMethod'"
                            :rules="tableRules.innspectionMethod">
                            <SHZY-select :list="methodData" v-model:bindValue="scope.row.innspectionMethod" label="name"
                                value="id"></SHZY-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="类型" width="150">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + '.type'">
                            <el-radio-group v-model='scope.row.type' size='small' @input="handleType(scope.row)">
                                <el-radio-button v-for="(item, index) in typeOptions" :key="index" :label="item.id">{{
                                    item.fullName }}</el-radio-button>
                            </el-radio-group>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="定量标准" width="140">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + ''" :rules="tableRules.quantitativeStandards">
                            <el-select v-model="scope.row.quantitativeStandards" size="mini" clearable
                                :disabled="scope.row.type != 'ration'">
                                <el-option v-for="( item, index ) in  quantitativeStandardsData " :key="index"
                                    :label="item.fullName" :value="item.enCode" />
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="标准值" width="150">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + '.standardValue'"
                            :rules="tableRules.standardValue">
                            <el-input v-model='scope.row.standardValue' clearable required
                                :disabled="scope.row.type != 'ration'" @input="handleAccuracy(scope.row)">
                            </el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="区间（最小值/最大值）" width="320">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + ''" :rules="tableRules.minimumValue">
                            <el-input v-model='scope.row.minimumValue' clearable required style="width: 120px;"
                                :disabled="scope.row.quantitativeStandards != '1' || scope.row.type != 'ration'">
                            </el-input>
                        </el-form-item>&nbsp;
                        <el-form-item :prop="'detailData.' + scope.$index + ''" :rules="tableRules.maximumValue">
                            <el-input v-model='scope.row.maximumValue' clearable required style="width:120px;"
                                :disabled="scope.row.quantitativeStandards != '1' || scope.row.type != 'ration'">
                            </el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="允差（下偏差/上偏差）" width="320">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + '.lowerDeviation'"
                            :rules="tableRules.lowerDeviation">
                            <el-input v-model='scope.row.lowerDeviation' clearable required style="width: 120px;"
                                :disabled="scope.row.quantitativeStandards != '7' || scope.row.type != 'ration'">
                            </el-input>
                        </el-form-item>&nbsp;
                        <el-form-item :prop="'detailData.' + scope.$index + '.upperDeviation'"
                            :rules="tableRules.upperDeviation">
                            <el-input v-model='scope.row.upperDeviation' clearable required style="width: 120px;"
                                :disabled="scope.row.quantitativeStandards != '7' || scope.row.type != 'ration'">
                            </el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="精度" width="100">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + '.accuracy'" :rules="tableRules.accuracy">
                            <el-input v-model='scope.row.accuracy' clearable required
                                :disabled="scope.row.type != 'ration'">
                            </el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="单位" width="140">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + ''" :rules="tableRules.unit">
                            <el-select v-model='scope.row.unit' placeholder='请选择' clearable filterable
                                :disabled="scope.row.type != 'ration'">
                                <el-option v-for="(item, index) in unitData" :key="index" :label="item.fullName"
                                    :value="item.fullName"></el-option>
                            </el-select>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="参考" width="150">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + '.referTo'">
                            <el-radio-group v-model='scope.row.referTo' size='small'>
                                <el-radio-button v-for="(item, index) in switchOptions" :key="index" :label="item.id">{{
                                    item.fullName }}</el-radio-button>
                            </el-radio-group>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="破坏性" width="150">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + '.destructiveness'">
                            <el-radio-group v-model='scope.row.destructiveness' size='small'>
                                <el-radio-button v-for="(item, index) in switchOptions" :key="index" :label="item.id">{{
                                    item.fullName }}</el-radio-button>
                            </el-radio-group>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column prop="field" label="备注" width="140">
                    <template slot-scope="scope">
                        <el-form-item :prop="'detailData.' + scope.$index + '.remarks'">
                            <el-input v-model='scope.row.remarks' clearable required>
                            </el-input>
                        </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="100" fixed="right">
                    <template slot-scope="scope">
                        <el-button type="text" @click="handleCopy(scope.row)">复制</el-button>
                        <el-button class="SHZY-table-delBtn" size="mini" type="text"
                            @click="handleDel(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-form>
        <div class="table-actions" @click="addHandle()">
            <el-button type="text" icon="el-icon-plus">添加检验项目</el-button>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false">{{ $t('common.cancelButton') }}</el-button>
            <el-button :loading="btnLoading" type="primary" @click="dataFormSubmit()">确 定</el-button>
        </span>
    </el-dialog>
</template>
    
<script>
import Sortable from 'sortablejs'
import { addIpqcInspectionitem } from '@/api/q1/business/ipqcInspectionLot'
export default {
    data() {
        const gLevelValidator = (rule, value, callback) => {
            if (this.dataForm.samplingType == "1") {
                if (!value || value.trim().length == 0) {
                    callback(new Error("请选择检验水平"));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        };
        const gStringencyValidator = (rule, value, callback) => {
            if (this.dataForm.samplingType == "1") {
                if (!value || value.trim().length == 0) {
                    callback(new Error("请选择国际严格度"));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        };
        const gQualityLimitValidator = (rule, value, callback) => {
            if (this.dataForm.samplingType == "1") {
                if (!value || value.trim().length == 0) {
                    callback(new Error("请选择国际质量限"));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        };
        const fixedSamplingQtyValidator = (rule, value, callback) => {
            if (this.dataForm.samplingType == "2" || this.dataForm.samplingType == "5") {
                if (!value || value.trim().length == 0) {
                    callback(new Error("请输入抽样数量"));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        };
        const fixedRatioValidator = (rule, value, callback) => {
            if (this.dataForm.samplingType == "3") {
                if (!value || value.trim().length == 0) {
                    callback(new Error("请输入抽样比例"));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        };
        const aQLValidator = (rule, value, callback) => {
            if (this.dataForm.samplingType == "4") {
                if (!value || value.trim().length == 0) {
                    callback(new Error("请选择自定义AQL"));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        };
        const innspectionCodeValidator = (rule, value, callback) => {
            if (!value || value.innspectionCode.trim().length == 0) {
                callback(new Error("请选择检验项目"));
            } else {
                if (value.innspectionEntry.trim().length != 0) {
                    let index = this.dataForm.detailData.findIndex(x => x.innspectionCode == value.innspectionCode && x.innspectionEntry == value.innspectionEntry && x.index != value.index)
                    if (index != -1) {
                        callback(new Error("检验项目与检验条目重复添加"));
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        };
        const innspectionEntryValidator = (rule, value, callback) => {
            if (!value || value.innspectionEntry.trim().length == 0) {
                callback(new Error("请选择检验条目"));
            } else {
                if (value.innspectionCode.trim().length != 0) {
                    let index = this.dataForm.detailData.findIndex(x => x.innspectionCode == value.innspectionCode && x.innspectionEntry == value.innspectionEntry && x.index != value.index)
                    if (index != -1) {
                        callback(new Error("检验项目与检验条目重复添加"));
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            }
        };
        const maximumValueValidator = (rule, value, callback) => {
            if (!value || value.maximumValue.length == 0) {
                callback(new Error("请输入最大值"));
            } else {
                var _reg = /^\d+(\.\d{0,6})?$/
                if (!_reg.test(value.maximumValue)) {
                    callback(new Error("只能输入正整数或小数"));
                } else {
                    if (value.quantitativeStandards == "1" && value.minimumValue.length != 0) {
                        if (value.maximumValue <= value.minimumValue) {
                            callback(new Error("最大值必须大于最小值"));
                        } else {
                            callback();
                        }
                    } else {
                        callback();
                    }
                }
            }
        };

        const minimumValueValidator = (rule, value, callback) => {
            if (!value || value.minimumValue.length == 0) {
                callback(new Error("请输入最小值"));
            } else {
                var _reg = /^\d+(\.\d{0,6})?$/
                if (!_reg.test(value.minimumValue)) {
                    callback(new Error("只能输入正整数或小数"));
                } else {
                    if (value.quantitativeStandards == "1" && value.maximumValue.length != 0) {
                        if (value.maximumValue <= value.minimumValue) {
                            callback(new Error("最小值必须小于最大值"));
                        } else {
                            callback();
                        }
                    } else {
                        callback();
                    }
                }
            }
        };
        const unitValidator = (rule, value, callback) => {
            if (!value || value.unit.trim().length == 0) {
                if (value.type == "ration") {
                    callback(new Error("请选择单位"));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        };
        const quantitativeStandardsValidator = (rule, value, callback) => {
            if (!value || value.quantitativeStandards.trim().length == 0) {
                if (value.type == "ration") {
                    callback(new Error("请选择定量标准"));
                } else {
                    callback();
                }
            } else {
                callback();
            }
        };

        return {
            btnLoading: false,
            visible: false,
            sampleTypeData: [],
            gLevelData: [],
            gStringencyData: [],
            gQualityLimitData: [],
            aqlData: [],
            projectData: [],
            itemData: [],
            methodData: [],
            quantitativeStandardsData: [],
            unitData: [],
            typeOptions: [{ 'fullName': "定量", 'id': "ration" }, { 'fullName': "定性", 'id': "qualitative" }],
            switchOptions: [{ 'fullName': "开启", 'id': "Y" }, { 'fullName': "关闭", 'id': "N" }],
            sortable: null,
            dataForm:
            {
                code: "",
                sampleId: "",
                productionQty: 0,
                samplingQty: 0,
                receivedQty: 0,
                rejectionQty: 0,
                samplingType: "",
                gLevel: "",
                gStringency: "",
                gQualityLimit: "",
                fixedSamplingQty: 0,
                fixedRatio: 0,
                aQL: "",
                detailData: [
                    // {
                    //     index: 0,
                    //     innspectionCode: "",
                    //     innspectionEntry: "",
                    //     innspectionMethod: "",
                    //     type: "ration",
                    //     quantitativeStandards: "",
                    //     standardValue: 0,
                    //     upperDeviation: 0,
                    //     lowerDeviation: 0,
                    //     maximumValue: 0,
                    //     minimumValue: 0,
                    //     accuracy: 0,
                    //     unit: "",
                    //     remarks: "",
                    //     fileInfo: [],
                    //     referTo: "N",
                    //     destructiveness: "N",
                    // }
                ]
            },
            rules: {
                samplingType: [
                    { required: true, message: '请选择抽样方案', trigger: '"blur"' },
                ],
                gLevel: [
                    { required: true, validator: gLevelValidator, trigger: '"blur"' }
                ],
                gStringency: [
                    { required: true, validator: gStringencyValidator, trigger: '"blur"' }
                ],
                gQualityLimit: [
                    { required: true, validator: gQualityLimitValidator, trigger: '"blur"' }
                ],
                fixedSamplingQty: [
                    { required: true, validator: fixedSamplingQtyValidator, trigger: '"blur"' },
                    { pattern: /^\d+$/, message: '只能输入正整数', trigger: 'blur' }
                ],
                fixedRatio: [
                    { required: true, validator: fixedRatioValidator, trigger: '"blur"' },
                    { pattern: /^\d+(\.\d{0,1})?$/, message: '只能输入正整数或小数', trigger: 'blur' }
                ],
                aQL: [
                    { required: true, validator: aQLValidator, trigger: '"blur"' }
                ]
            },
            tableRules: {
                innspectionCode: [,
                    { required: true, validator: innspectionCodeValidator, trigger: '"blur"' }
                ],
                innspectionEntry: [
                    { required: true, validator: innspectionEntryValidator, trigger: '"blur"' }
                ],
                innspectionMethod: [
                    { required: true, message: '请选择检验方法', trigger: '"blur"' }
                ],
                quantitativeStandards: [
                    { required: true, validator: quantitativeStandardsValidator, trigger: '"blur"' }
                ],
                standardValue: [
                    { required: true, message: '请输入标准值', trigger: '"blur"' },
                    { pattern: /^\d+(\.\d{0,6})?$/, message: '只能输入正整数或小数', trigger: 'blur' }
                ],
                upperDeviation: [
                    { required: true, message: '请输入上偏差', trigger: '"blur"' },
                    { pattern: /^\d+(\.\d{0,6})?$/, message: '只能输入正整数或小数', trigger: 'blur' }
                ],
                lowerDeviation: [
                    { required: true, message: '请输入下偏差', trigger: '"blur"' },
                    { pattern: /^\d+(\.\d{0,6})?$/, message: '只能输入正整数或小数', trigger: 'blur' }
                ],
                maximumValue: [
                    { required: true, validator: maximumValueValidator, trigger: '"blur"' }
                ],
                minimumValue: [
                    { required: true, validator: minimumValueValidator, trigger: '"blur"' }
                ],
                accuracy: [
                    { required: true, message: '请输入精度', trigger: '"blur"' },
                    { pattern: /^\d+$/, message: '只能输入正整数', trigger: 'blur' }
                ],
                unit: [
                    { required: true, validator: unitValidator, trigger: '"blur"' }
                ]
            }
        }
    },
    created() {
        this.getDictionaryData();
    },
    methods: {
        getDictionaryData() {
            this.$store.dispatch('base/getDictionaryData', { sort: 'sampleType' }).then((res) => {
                this.sampleTypeData = res
            })
            this.$store.dispatch('base/getDictionaryData', { sort: 'gLevel' }).then((res) => {
                this.gLevelData = res
            })
            this.$store.dispatch('base/getDictionaryData', { sort: 'gStringency' }).then((res) => {
                this.gStringencyData = res
            })
            this.$store.dispatch('base/getDictionaryData', { sort: 'gQualityLimit' }).then((res) => {
                this.gQualityLimitData = res
            })
            this.$store.dispatch('base/getDictionaryData', { sort: 'quantitativeStandards' }).then((res) => {
                this.quantitativeStandardsData = res;
            })
            this.$store.dispatch('base/getDictionaryData', { sort: 'InspectionUnit' }).then((res) => {
                this.unitData = res
            })
            this.$store.dispatch('qms/getAQLData').then((res) => {
                this.aqlData = res
            })
            this.$store.dispatch('qms/getInnspectionItemsData').then((res) => {
                this.projectData = res
            })
            this.$store.dispatch('qms/getInnspectionEntryData').then((res) => {
                this.itemData = res
            })
            this.$store.dispatch('qms/getInnspectionMethodData').then((res) => {
                this.methodData = res
            })
        },
        init(code, productionQty, row) {
            this.reset()
            this.dataForm.code = code
            this.dataForm.productionQty = productionQty
            if (row) {
                this.dataForm.sampleId = row.SampleId
                this.dataForm.samplingQty = row.SamplingQty
                this.dataForm.receivedQty = row.ReceivedQty
                this.dataForm.rejectionQty = row.RejectionQty
            }
            this.visible = true
            this.$nextTick(() => {
                this.$refs['elForm'].resetFields();
                this.$refs["tableForm"].resetFields();
                this.setSort()
            })
        },
        reset() {
            this.dataForm = {
                code: "",
                sampleId: "",
                productionQty: 0,
                samplingQty: 0,
                receivedQty: 0,
                rejectionQty: 0,
                samplingType: "",
                gLevel: "",
                gStringency: "",
                gQualityLimit: "",
                fixedSamplingQty: 0,
                fixedRatio: 0,
                aQL: "",
                detailData: [
                    // {
                    //     index: 0,
                    //     innspectionCode: "",
                    //     innspectionEntry: "",
                    //     innspectionMethod: "",
                    //     type: "ration",
                    //     quantitativeStandards: "",
                    //     standardValue: 0,
                    //     upperDeviation: 0,
                    //     lowerDeviation: 0,
                    //     maximumValue: 0,
                    //     minimumValue: 0,
                    //     accuracy: 0,
                    //     unit: "",
                    //     remarks: "",
                    //     fileInfo: [],
                    //     referTo: "N",
                    //     destructiveness: "N",
                    // }
                ]
            }
        },
        setSort() {
            const el = this.$refs.dragTable.$el.querySelectorAll('.el-table__body-wrapper > table > tbody')[0]
            this.sortable = Sortable.create(el, {
                sort: true,
                ghostClass: 'sortable-ghost', // Class name for the drop placeholder,
                setData: function (dataTransfer) {
                    // to avoid Firefox bug
                    // Detail see : https://github.com/RubaXa/Sortable/issues/1012
                    dataTransfer.setData('Text', '')
                },
                onEnd: evt => {
                    const targetRow = this.dataForm.detailData.splice(evt.oldIndex, 1)[0]
                    this.dataForm.detailData.splice(evt.newIndex, 0, targetRow)
                },
                handle: '.drag-handler',
            })
        },
        handleType(row) {
            if (row.type == "qualitative") {
                row.quantitativeStandards = ""
                row.standardValue = 0
                row.minimumValue = 0
                row.maximumValue = 0
                row.lowerDeviation = 0
                row.upperDeviation = 0
                row.accuracy = 0
                row.unit = ""
            }
        },
        handleAccuracy(row) {
            const _arr = row.standardValue.split('.');
            if (_arr.length > 1) {
                row.accuracy = _arr[1].length
            } else {
                row.accuracy = 0
            }
        },
        handleCopy(row) {
            let index = this.dataForm.detailData.length, item = {}
            item = {
                ...row
            }
            item.index = index
            this.dataForm.detailData.push(item)
        },
        handleDel(index, row) {
            this.dataForm.detailData.splice(index, 1)
        },
        addHandle() {
            let index = this.dataForm.detailData.length, item = {}
            item = {
                index: index,
                innspectionCode: "",
                innspectionEntry: "",
                innspectionMethod: "",
                type: "ration",
                quantitativeStandards: "",
                standardValue: 0,
                upperDeviation: 0,
                lowerDeviation: 0,
                maximumValue: 0,
                minimumValue: 0,
                accuracy: 0,
                unit: "",
                remarks: "",
                fileInfo: [],
                referTo: "N",
                destructiveness: "N",
            }
            this.dataForm.detailData.push(item)
        },
        dataFormSubmit() {

            let check = true;
            if (this.dataForm.sampleId == "") {
                this.$refs['elForm'].validate((valid) => { check = valid })
            }
            if (check) {
                if (this.dataForm.detailData.length == 0) {
                    this.$message({
                        type: 'error',
                        message: '请添加检验项目',
                        duration: 1500,
                    })
                    return
                }
                this.$refs['tableForm'].validate((valid) => {
                    if (valid) {
                        this.btnLoading = true
                        addIpqcInspectionitem(this.dataForm).then((res) => {
                            this.btnLoading = false;
                            this.$message({
                                message: res.msg,
                                type: 'success',
                                duration: 1000,
                                onClose: () => {
                                    this.visible = false
                                    this.$emit('refresh', true)
                                }
                            })
                        }).catch((res) => {
                            this.btnLoading = false;
                        })
                    }
                });
            }
        }
    }
}
</script>